'''
#define EQ(a,b) (fabs((a)-(b)) < (EPS)) //macro for == of doubles
#define LS(a,b) (((b)-(a)) > (EPS)) //macro for < of doubles
#define LE(a,b) (((a)-(b)) <= (EPS)) //macro for <= of doubles


@author: noako
'''

EPSILON = 1e-9

# a subclass of float with fuzzy comparison operators 
class FuzzyFloat(float):
    # override comparisons
    def __eq__(self, other):
        return float(abs(self - other)) < EPSILON 
    def __ne__(self, other):
        return float(abs(self - other)) >= EPSILON
    def __lt__(self, other):
        return float(other - self) > EPSILON
    def __le__(self, other):
        return float(self - other) <= EPSILON
    def __gt__(self, other):
        return float(self - other) > EPSILON
    def __ge__(self, other):
        return float(other - self) <= EPSILON

    # override operators so that they return FuzzyFloats rather than regular floats
    def __add__(self, other):
        return FuzzyFloat(float(self) + float(other))
    def __sub__(self, other):
        return FuzzyFloat(float(self) - float(other))
    def __mul__(self, other):
        return FuzzyFloat(float(self) * float(other))
    def __truediv__(self, other):
        if other == 0.0: #fuzzy comparison
            raise ZeroDivisionError
        return FuzzyFloat(float(self) / float(other))